<!doctype html>
<html lang=china>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>外边距塌陷</title>
    <style>

        .father{
            width: 400px;
            height: 400px;
            background-color: skyblue;
            /*border: 1px solid transparent;*/
            /*flex布局,让2个div盒子在一行*/
            /*display: flex;*/
            /*justify-content: space-between;*/


            /*!*版心居中 左右自动*!*/
            /*margin:0 auto;*/
        }
        .son{
            width: 100px;
            height: 100px;
            background-color: black;
            margin-top: 50px;
        }

        
  /*站在父盒子角度来说: 设置子盒子上外边距(margin-top),父盒子也跟着往下移动
    解决父盒子跟着下移的问题:
    1. 如果子盒子想往下移动,不设置margin-top，给父盒子设置上内边距(padding-top)
       代码:
            .father{
                width: 400px;
                height: 400px;
                background-color: skyblue;
                padding-top: 50px;
            }
            .son{
                width: 100px;
                height: 100px;
                background-color: black;
            }
    2.如果子盒子必须设置margin-top的情况下,给父盒子设置overflow:hidden
       代码:
            .father{
                width: 400px;
                height: 400px;
                background-color: skyblue;
                overflow:hidden;
            }
            .son{
                width: 100px;
                height: 100px;
                background-color: black;
                margin-top: 50px;
            }

     除了设置overflow:hidden之外,还可以给父盒子设置border:1px solid transparent;
     这样父盒子也不会跟着子盒子往下移动:
       代码:
            .father{
                width: 400px;
                height: 400px;
                background-color: skyblue;
                border: 1px solid transparent;
            }
            .son{
                width: 100px;
                height: 100px;
                background-color: black;
                margin-top: 50px;
            }
    */
    </style>
</head>
<body>
<div class="father">
    <div class="son"></div>
    <div class="son2"></div>
</div>


</body>
</html>